<?php
class Vs_User_Table
	extends Vs_Table 
	
{
    protected $_name = 'Users';
	protected $_primary = 'userId';
    
	protected $_keys = array(
        'userId' => Zend_Db::INT_TYPE,
        'email'   => null,
        'name'   => null,
        'surname'   => null,
        'birthdate'   => null,
        'sex'   => Zend_Db::INT_TYPE,
        'cityId'   => Zend_Db::INT_TYPE,
        'type'   => Zend_Db::INT_TYPE,
        'password'   => null,
        'active'   => null,
        'code'   => null
    );
	
	protected $_nulls = array(
		'name','surname','birthdate', 'sex', 
		'cityId', 'password', 'code'
	);
	
    public function getByAccount( $email, $password, $active = 1)
    {
		return 
			$this->_db->fetchRow(
				$this->select()
					->where('active = ?', $active, Zend_Db::INT_TYPE)
					->where('email = ?', $email)
					->where('password = ?', $password)					
			);
	}
	
	
//	public function getByParams( $params, $offset = null, $limit = null, $order = null ){
//		
//		$select = $this->select();
//		
//		if ( isset($params['type'])){
//			$this->_whereVal($select, 'type', $params['type'], Zend_Db::INT_TYPE);
//		}
//		
//		if ( isset($params['cityId'])){
//			$this->_whereVal($select, 'cityId', $params['cityId'], Zend_Db::INT_TYPE);
//		}
//		
//		if ( isset($params['sex'])){
//			$this->_whereVal($select, 'sex', $params['sex'], Zend_Db::INT_TYPE);
//		}
//		
//		if ( $order ){
//			$select->order( $order );
//		}
//		
//		if ( $limit && !is_null($offset) ){
//			$select->limit( $limit, $offset );
//		}
//		
//		return $this->_db->fetchAssoc($select);
//	}
	
//	public function countByParams( $params )
//	{
//		$select = $this->select()
//				->from($this, array('count' => 'COUNT(1)'));
//		
//		if ( isset($params['type'])){
//			$this->_whereVal($select, 'type', $params['type'], Zend_Db::INT_TYPE);
//		}
//		
//		if ( isset($params['cityId'])){
//			$this->_whereVal($select, 'cityId', $params['cityId'], Zend_Db::INT_TYPE);
//		}
//		
//		if ( isset($params['sex'])){
//			$this->_whereVal($select, 'sex', $params['sex'], Zend_Db::INT_TYPE);
//		}
//		
//		$result = $this->_db->fetchRow($select);
//		
//		return $result['count'];
//	}
	
	
}
